<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class menu_service{
	private $CI;
	function __construct() { 
		$this->CI = &get_instance();
		$this->CI->load->model('Menu_model');
	}

	/**  
	* 获取目录列表
	* @access public 
	* @return array
	*/  
	public function getMenu($park_id) {
		$menu=$this->CI->Menu_model->get_list(array('park_id'=>$park_id),'order asc');
		if($menu){
			$menu=listToTree($menu);
		}
		else{
			$menu=array();
		}
		return $menu;
	}

	/**  
	* 后台用的菜单配置树
	* @access public 
	* @return array
	*/  
	public function getMenuTree($park_id) {
		//先取一级
		$menu=$this->CI->Menu_model->get_list(array('pid'=>0,'park_id'=>$park_id),'order asc');
		foreach ($menu as $k => $v) {
			$menu[$k]['text']='<img src="'.base_url().'public/home/images/park.png" style="height:25px; width:25px; margin-right:5px;"><a title="'.$v['name'].'" href="javascript:void(0)">'.$v['name'].(isNullOrEmpty($v['href'])?'':'&nbsp;&nbsp;&nbsp;&nbsp;地址:'.$v['href']).'</a>';
			$menu[$k]['after_html']='<div class="list icon-list list-icon button_z">
															<div class="list-content">
																<div class="list-content-item reset-name" onclick="addMenu(this)" data-id="'.$v['id'].'"><i class="icon-edit  list-content-item-icon"></i>添加子菜单</div>
																<div class="list-content-item reset-name" onclick="editMenu(this)" data-id="'.$v['id'].'"><i class="icon-edit  list-content-item-icon"></i>编辑</div>
																<div class="list-content-item delete" onclick="delMenu(this)" data-id="'.$v['id'].'"><i class="icon-remove-sign  list-content-item-icon"></i>删除</div>
															</div>
														</div>';
			$sub_menu=$this->CI->Menu_model->get_list(array('pid'=>$v['id'],'park_id'=>$park_id),'order asc');
			if($sub_menu){
				$menu[$k]['nodes']=$sub_menu;
				foreach ($menu[$k]['nodes'] as $k1 => $v1) {
					$menu[$k]['nodes'][$k1]['text']='<img src="'.base_url().'public/home/images/article-type.png" style="height:25px; width:25px; margin-right:5px;"><a title="'.$v1['name'].'" href="javascript:void(0)">'.$v1['name'].(isNullOrEmpty($v1['href'])?'':'&nbsp;&nbsp;&nbsp;&nbsp;地址:'.$v1['href']).'</a>';
					$menu[$k]['nodes'][$k1]['after_html']='<div class="list icon-list list-icon button_z">
																		<div class="list-content">
																			<div class="list-content-item reset-name" onclick="editMenu(this)" data-id="'.$v1['id'].'"><i class="icon-edit  list-content-item-icon"></i>编辑</div>
																			<div class="list-content-item delete" onclick="delMenu(this)" data-id="'.$v1['id'].'"><i class="icon-remove-sign  list-content-item-icon"></i>删除</div>
																		</div>
																	</div>';
				}
			}
		}
		return $menu;
	}
	
}